﻿#pragma once

#include <tuple>
#include <oleauto.h>

/**
 * 同时为多个VARIANT变量提供初始化和清理保护
 */
template <typename... Args>
class com_variant_guard
{
public:
    explicit com_variant_guard(Args&... args) : variants(args...)
    {
        std::apply([](Args&... args) { (..., VariantInit(&args)); }, variants);
    }

    ~com_variant_guard()
    {
        std::apply([](Args&... args) { (..., VariantClear(&args)); }, variants);
    }
private:
    std::tuple<Args&...> variants;
};
